jclass={
    initPage:function(){
        // 绑定dom对象
        this.obj = {
            searchText:$('#searchText'),
        };
        // 声明全局变量
        this.data = {
            datatable:[],
            tableParams: {
                platformName: '',
                areaId: '',
                startTime:'',
                endTime:'',
                page:1,
                size:10
            },
            tableRecordStatus:['已取消','交换中','异常断开']
        };
        this.getTableList();
        // this.creatTable();
        this.init();
        this.bindEvent();
    },
    init() {
        let that =this
        $('#datepickerTime').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function (type) {
                // console.info(this.$input.eq(0).val(), this.$input.eq(1).val());
                that.data.tableParams.startTime = this.$input.eq(0).val()
                that.data.tableParams.endTime = this.$input.eq(1).val()
            }
        });
        this.diquSelceted()
    },
    setCheck() {
        this.data.zTree = $.fn.zTree.getZTreeObj("treeDemo");
        this.data.zTree.setting.check.chkboxType = {Y: "s", N: "s"};
    },
    bindEvent() {
        $("#resetClick").click(() => {
            $("#search_input_platform").val("")
            $(".item.rtable_input").find("input").val("")
            $("#datepickerTime input").val("")

            this.data.tableParams = {
                platformName: '',
                areaId: '',
                startTime:'',
                endTime:'',
                page:1,
                size:10
            }
        })
        $("#searchClick").click(() => {
            this.getTableList()
        })
    },
    /**
     * 请求地区数据
     * */
    diquSelceted: function() {
        jrequest.get("/api/assessMent/selectByArea",{}).then(res => {
            let data = res.data
            data[0].code = 1;
            $.each(data[0].cityAreaVOS, function(i, dom) {
                data[0].cityAreaVOS[i].code = 2;
                $.each(data[0].cityAreaVOS[i].cityAreaVOS, function(j, dom) {
                    data[0].cityAreaVOS[i].cityAreaVOS[j].code = 3;
                })
            })
            this.creatMainRido("excahnge_pqrm_main", data, "cityAreaVOS", "code");
        })
    },
    /**
     * 下拉框
     * */
    creatMainRido: function(id, attr, child, jibie) {
        $(id).html("");
        var sttrdiv = "";
        for(var i = 0; i < 3; i++) {
            sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
                "<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
                "</ul>" +
                "</div>"
        };
        $(".qrm-main").html(sttrdiv);
        var str = "";
        $("#qrm-border1").html("");
        var forTree = function(o) {
            for(var i = 0; i < o.length; i++) {
                var urlstr = "";
                try {
                    urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
                    str += urlstr;
                    if(o[i][child] != null) {
                        forTree(o[i][child]);
                    }
                    str += "</ul>";
                } catch(e) {}
            }
            return str;
        };
        $("#qrm-border1").html(forTree(attr));
    },
    getTableList() {
        $("#jid_loading").show()
        this.data.tableParams.platformName = $("#search_input_platfrom").val()
        if ($(".item.rtable_input").find("input").val()) this.data.tableParams.areaId = $(".item.rtable_input").find("input").attr("data-id")
        else this.data.tableParams.areaId = ''
        jrequest.get("/api/exchange_information",this.data.tableParams).then(res => {
            res.data.forEach(item => {
                item.statusName = this.data.tableRecordStatus[Number(item.status)]
            })
            this.data.datatable = res.data
            $("#jtable_exchangeplatform").bootstrapTable('destroy');
            this.creatTable(res)
            $("#jid_loading").hide()
            // $("#jtable_exchangeplatform").bootstrapTable('load',res.data);
        })
    },
    tableEvent:function(id,data,columns,paginationShow,total){
        let that = this
        $('#' + id).bootstrapTable({
            method: 'get',
            cache: false,
            height: 320,
            pagination: paginationShow,
            pageSize: that.data.tableParams.size,
            pageNumber:that.data.tableParams.page,
            showColumns: false,
            striped: true,
            columns: columns,
            sidePagination: 'server', // client or server
            totalRows: total,
            data :data,
            onPageChange: function (size, number) {
                console.log(number)
                that.data.tableParams.page = number
                that.data.tableParams.size = size
                that.getTableList()
            },
            formatNoMatches: function(){
                return '暂无数据';
            }
        });
    },
    creatTable:function(res){
        var self=this;
        var columnsOne = [
            {
                title : '序号',
                align: "center",
                formatter: function (value, row, index) {
                    //获取每页显示的数量
                    var pageSize=self.data.tableParams.size;
                    //获取当前是第几页
                    var pageNumber=self.data.tableParams.page;
                    //返回序号，注意index是从0开始的，所以要加上1
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },
            {
              field: "areaName",
              title: "地区",
              visible: true
            },
            {
              field: "platformName",
              title: "交换平台",
              visible: true
            },
            {
              field: "startTime",
              title: "开始时间",
              visible: true
            },
            {
              field: "endTime",
              title: "结束时间",
              visible: true
            },
            {
              field: "statusName",
              title: "状态",
              visible: true
            }
        ];
        self.tableEvent("jtable_exchangeplatform",res.data,columnsOne,true,res.total);
    }
}


$(function(){
    jclass.initPage();
});


















